package prefuse.vensim;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;


public class ReadText {
	private BufferedReader br;
	private String line;
	private static HashMap<String,String> innerMap= new HashMap<String,String>();
	private static Map<String,HashMap<String,String>>  ValueMap = new HashMap<String,HashMap<String,String>>();
	private double value[] = new double[]{};
	public static HashMap<String,String> IHashMap;
	
	public  ReadText(String txtFilename) throws IOException{
		
		br = new BufferedReader(new FileReader(txtFilename));
		int OuterMapSize = 0;
		String OuterKey = "";
		
		while((line = br.readLine())!=null){
			
		
			
			
//			OuterMapSize = ValueMap.size();
			String[] columns = line.split("	");
			
			if(!OuterKey.equals(columns[0])){
				innerMap= new HashMap<String,String>();
			}
			System.out.println("columns[0]: this is in ReadText"+columns[0]);
			
			innerMap.put(columns[1],columns[2]);	
			System.out.println("innerMap.size() "+innerMap.size());
			ValueMap.put(columns[0],innerMap);
			OuterKey = columns[0];
			
			
		}

	
		
	}

	public void searchMap(String s,String[] time) throws IOException{	
	
		
		System.out.println("this isIHashMap: "+IHashMap);
		
		value = new double[]{};
		
		if(ValueMap.get(s)!=null){
			IHashMap = ValueMap.get(s);
			System.out.println("i am here s is : "+s);
		}
		
		if ( time == null ){
			time = new String[]{""};
			}
		
		
		
		System.out.println("length of time I am in ReadText"+time.length);
		
		for(int i=0; i<time.length; i++){
			
			System.out.println("length of value"+time[i]);
			if(value==null){
				value[0] = Double.valueOf(IHashMap.get(time[i]));
				System.out.println("bbbb" + value[0]);
			}
			else{
				System.out.println("this is time: " + time[i]);
				value=Arrays.copyOf(value, value.length+1);
		//		System.out.println("the value is : " + Double.valueOf(IHashMap.get(time[i])));
				value[value.length-1]=Double.valueOf(IHashMap.get(time[i]));
				
			}
		}
		
	}
	public double[] getValue(){
		return value;
	}
	public double getValue(String s,String time){
		HashMap<String,String> IHashMap = (HashMap) ValueMap.get(s);
		double temptime = Double.valueOf(time);
		double value = Double.valueOf(IHashMap.get(temptime));
		return value;
	}
	public static void main(String agrs[])
	 {  
		try {
			String[] t = new String[]{"0","1","2","3","4","5"};
			ReadText a = new ReadText("C:\\tmp\\ann880Test1.txt");
			a.searchMap("NegativeOfCumulativeWNVSymptomaticCases",t);
			double[] b = a.getValue();
			
			for(int i=0; i<b.length; i++){
				System.out.println("the array value is : " + b[i]);
			}

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	 }
}
